package store.lunangangster.engine.impl;

import java.util.Calendar;
import java.util.Date;
import org.joda.time.DateTime;
import store.lunangangster.engine.EngineClock;

public class ProcessEngineClock implements EngineClock {

  protected static volatile DateTime CURRENT_DATE;

  @Override
  public Date now() {
    return CURRENT_DATE == null ? new Date() : CURRENT_DATE.toDate();
  }

  @Override
  public void setCurrentDate(Calendar currentDate) {
    CURRENT_DATE = new DateTime(currentDate);
  }

  @Override
  public void setCurrentDate(DateTime datetime) {
    CURRENT_DATE = datetime;
  }

  @Override
  public void reset() {
    CURRENT_DATE = null;
  }
}
